package Dao;

import Modelo.Hospede;
import java.util.List;

/**
 *
 * @author kassio
 */
public class DaoHospede extends Dao<Hospede>{
    public DaoHospede() {
        super();
    }

    @Override
    public List<Hospede> findAll() {
        return getRepositorio().getHospedes();
    }

    @Override
    public boolean remove(Hospede obj) {
        Hospede hospede = find(obj.getId());
        boolean remove = getRepositorio().getHospedes().remove(hospede);
        salvarRepositorio();
        return remove;
    }

    @Override
    public boolean add(Hospede obj) {
        List<Hospede> lista = getRepositorio().getHospedes();
        int indice = (lista.size())-1;
        
        if (indice >= 0)
            obj.setId(lista.get(indice).getId()+1);            
        else
            obj.setId(1);  
            
        boolean add = getRepositorio().getHospedes().add(obj);
        salvarRepositorio();
        return add;
    }

    @Override
    public void edit(Hospede obj) {
        Hospede temp = find(obj.getId());
        temp.getData(obj);
        salvarRepositorio();
    }

    @Override
    public Hospede find(Object key) {
        for (Hospede h : getRepositorio().getHospedes()) {
            if (h.getId() == (Integer)key) {
                return h;
            }
        }
        return null;
    }
    

    
}
